<?php

namespace App\Providers;

use App\Models\Chapter;
use App\Models\Repository;
use App\Policies\ChapterPolicy;
use App\Policies\RepositoryPolicy;
use App\Policies\UserPolicy;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;

class AuthServiceProvider extends ServiceProvider
{
    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
        Chapter::class => ChapterPolicy::class,
        Repository::class => RepositoryPolicy::class,
    ];

    /**
     * Register any authentication / authorization services.
     *
     * @return void
     */
    public function boot()
    {
        $this->registerPolicies();
        Gate::resource('repositories', RepositoryPolicy::class);
        Gate::define('repositories.create-chapter', 'App\Policies\RepositoryPolicy@createChapter');
        Gate::define('repositories.switch-chapter', 'App\Policies\RepositoryPolicy@createChapter');
        Gate::define('repositories.fork', 'App\Policies\RepositoryPolicy@fork');
        Gate::define('repositories.push', 'App\Policies\RepositoryPolicy@push');
        Gate::define('repositories.pull', 'App\Policies\RepositoryPolicy@pull');

        Gate::resource('chapters', ChapterPolicy::class, []);
        Gate::resource('users', UserPolicy::class, []);
        Gate::define('comments.delete', 'App\Policies\CommentPolicy@delete');
    }
}
